package com.casework


import org.apache.commons.lang.builder.HashCodeBuilder

class LegalCaseNaceFullDescription implements Serializable{
    LegalCase legalCase
    Nace description

    boolean equals(other) {
		if (!(other instanceof LegalCaseNaceFullDescription)) {
			return false
		}

		other.legalCase?.id == legalCase?.id &&
			other.description?.id == description?.id
	}

	int hashCode() {
		def builder = new HashCodeBuilder()
		if (legalCase) builder.append(legalCase.id)
		if (description) builder.append(description.id)
		builder.toHashCode()
	}

    static LegalCaseNaceFullDescription get(long legalCaseId, long descriptionId) {
		find 'from LegalCaseNaceFullDescription where legalCase.id=:legalCaseId and description.id=:descriptionId',
			[legalCaseId: legalCaseId, descriptionId: descriptionId]
	}

	static LegalCaseNaceFullDescription create(LegalCase legalCase, Nace description, boolean flush = false) {
		new LegalCaseNaceFullDescription(legalCase: legalCase, description: description).save(flush: flush, insert: true)
	}

	static boolean remove(LegalCase legalCase, Nace description, boolean flush = false) {
		LegalCaseNaceFullDescription instance = LegalCaseNaceFullDescription.findByLegalCaseAndDescription(legalCase, description)
		instance ? instance.delete(flush: flush) : false
	}


	static mapping = {
		id composite: ['description', 'legalCase']
		version false
	}
}
